
const Mock =require('mockjs')
const getComponentList=require('./data/getComponentList')
const Random=Mock.Random
const getQuestionList=require('./data/getQuestionList')
const { url } = require('koa-router')
module.exports =[
  {

    //获取单个问卷信息
    url:'/api/question/:id',
    method:'get',
    response(){
      return{
        errno:0,
        data:{
          title:'',
          desc:'',
          js:'',
          css:'',
          isPublished: true,
          id:Random.id(),
          title:Random.title(),
          componentList:getComponentList()
        }
        // msg:'错误'
      }
    }
  },
  //创建问卷
  {
    url:'/api/question',
    method:'post',
    response(){
      return{
        errno:0,
        data:{
          id:Random.id()
        }
      }
    }
  },
  {
    //获取查询问卷列表
    url: '/api/question',
    method: 'get',
    response(ctx){
      const {url='',query={}}=ctx
      const isDeleted=url.indexOf('isDeleted=true')>=0
      const isStar=url.indexOf('isStar=true')>=0
      const pageSize=parseInt(query.pageSize) || 10
      
      return{
        errno:0,
        data:{
          list:getQuestionList({len:pageSize,isStar,isDeleted}),
          total:100
        }
      }
    }
  },{
    //更新问卷
    url: '/api/question/:id',
    method:'patch',
    response(){
        return {
          errno:0
        }
      }
    
  },{
    url:'/api/question/duplicate/:id',
    method:'post',
    response(){
      return {
        errno:0,
        data:{
          id:Random.id()
        }
      }
    }
  },{
    //批量删除
    url:'/api/question',
    method:'delete',
    response(){
      console.log(url)
      return {
        errno:0
      }
    }

  }
]